<?php

class Controller_Admin_User_Edit  extends Controller_Admin_Abstract
{
	function execute($request)
	{
		$form = new Form_Admin_User_Edit;

		$id = (int)$request -> getParam('_id');

		$user = Mongo_Document::factory('user', $id);

		if ($request -> isGet())
		{
			$user -> load();
			$array = $user -> as_array();
			$form -> setValues($array);
		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$value = $form -> getValues();
			$user -> is_approved = intval($value['is_approved']);
			$user -> is_verified = intval($value['is_verified']);
			$user -> is_active = intval($value['is_active']);
			$user -> gender = $value['gender'];
			$user -> level_id = intval($value['level_id']);
			$user -> facebook = $value['facebook'];
			$user -> twitter = $value['twitter'];
			$user -> yahoo = $value['yahoo'];
			$user -> msn = $value['msn'];
			$user -> bod = $value['bod'];
			$user -> save();
		}
		$request -> response = View::render($data = array('form' => $form), 'controller/admin/edit.tpl');
	}

}
